package com.yxy.system.service;

import cn.orionsec.kit.lang.constant.Const;
import cn.orionsec.kit.lang.define.thread.ExecutorBuilder;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public interface ExecThreadPools {

    /**
     * 批量上传任务线程池
     */
    ThreadPoolExecutor UPLOAD_TASK = ExecutorBuilder.create()
            .namedThreadFactory("upload-task-")
            .corePoolSize(1)
            .maxPoolSize(Integer.MAX_VALUE)
            .keepAliveTime(1000 * 60)
            .workQueue(new SynchronousQueue<>())
            .allowCoreThreadTimeout(true)
            .build();

    /**
     * 批量脚本主机线程池
     */
    ThreadPoolExecutor COMMAND_HOST = ExecutorBuilder.create()
            .namedThreadFactory("command-host-")
            .corePoolSize(1)
            .maxPoolSize(Integer.MAX_VALUE)
            .keepAliveTime(1000 * 60)
            .workQueue(new SynchronousQueue<>())
            .allowCoreThreadTimeout(true)
            .build();

    ThreadPoolExecutor COMMAND_HOST_WORKER = ExecutorBuilder.create()
            .namedThreadFactory("command-host-worker-")
            .corePoolSize(10)
            .maxPoolSize(100)  // 控制并发主机数量
            .keepAliveTime(30, TimeUnit.SECONDS)
            .workQueue(new LinkedBlockingQueue<>(2000))
            .build();

    /**
     * 超时检查线程池
     */
    ThreadPoolExecutor TIMEOUT_CHECK = ExecutorBuilder.create()
            .namedThreadFactory("timeout-check-")
            .corePoolSize(1)
            .maxPoolSize(Integer.MAX_VALUE)
            .keepAliveTime(Const.MS_S_60)
            .workQueue(new SynchronousQueue<>())
            .allowCoreThreadTimeout(true)
            .build();
}
